package sender

import (
	"github.com/go-vgo/robotgo"
	hook "github.com/robotn/gohook"
	"net"
)

var moveX = 0

func WatchKeyboard(conn *net.UDPConn) {
	//把所有的事件都监听

	event := robotgo.EventStart()
	for {
		e := <-event
		switch e.Kind {
		case hook.KeyDown:
		case hook.KeyUp:
		case hook.KeyHold:
		case hook.MouseMove:
			SendMouse(conn, &e)
		case hook.MouseDown:
			SendMouse(conn, &e)
		case hook.MouseUp:
			SendMouse(conn, &e)
		case hook.MouseWheel:
			SendMouse(conn, &e)
		}
	}
}

func SendMouse(conn *net.UDPConn, event *hook.Event) {
	n, e := conn.Write(NewMessageFromEvent(event).Serialize())
	if e != nil {
		println(e.Error())
	}
	println("send len=", n)
}
